// index.js
// 获取应用实例
const app = getApp()
wx.cloud.init()
const db = wx.cloud.database()

Page({
  data: {
    background: [{
        img:'../../images/l1.jpg',
        sale:"每房仅限3席",
        title:"新房尝鲜5折起",
        select:"查看特惠房源"
      }, {
        img:'../../images/l2.jpg',
        sale:"独家特惠8折起",
        title:"去南方 享夏日闲情",
        select:"查看特惠房源"
      }, {
        img:'../../images/l3.jpg',
        sale:"每房仅限3席",
        title:"新房尝鲜5折起",
        select:"查看特惠房源"
        }],
      indicatorDots: true,
      vertical: true,
      autoplay: true,
      circular: false,
      interval: 2000,
      duration: 500,
      previousMargin: 0,
      nextMargin: 0,
      // 选择地点
      address: "",
      // 选择日期
      date:"2021-07-03",
      nav_list:[{
        img:"../../images/house.png",
        title:"整个房源",
        href:""
      },{
        img:"../../images/cook.png",
        title:"可以做饭",
        href:""
      },{
        img:"../../images/medal.png",
        title:"超赞房东",
        href:""
      },{
        img:"../../images/medal2.png",
        title:"热门榜单",
        href:"/pages/bd/bd"
      },{
        img:"../../images/house2.png",
        title:"特惠房源",
        href:""
      }],
      loc:["成都","上海","重庆","长沙"],
      // 下标
      i:0,
      safe:[{
        img:'../../images/safe1.png',
        title:"安心房源保障",
        text:"人工审核所有中国房源页面信息，入住更放心"
      },{
        img:"../../images/safe2.png",
        title:"专业中文客服",
        text:"中国大陆支持热线（+86）400-022-1666，境外旅行支持专线 +86-10-8783-3463"
      },{
        img:'../../images/safe3.png',
        title:"旅行安全保障",
        text:"多重风险控制设计，全方位保障您的行程安全"
      }],
      like:[{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like1.jpeg",
        title:"整套公寓型住宅·1室1卫1床",
        text:"星享会复式大床落地窗公寓/近琶洲会展/羊城创意园/直达珠江新城天河CBD/广州塔K11/海心桥",
        star:"../../images/star.png",
        comment:"413",
        price:"￥238"
      },{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like2.jpg",
        title:"整套酒店式公寓·1室1.5卫1床",
        text:"【临江大床/简约雅致/2米大窗】近北京路、海珠广场、珠江夜游码头，打卡珠江岸、浪漫休闲，寻味粤式美食",
        star:"../../images/star.png",
        comment:"46",
        price:"￥212"
      },{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like3.jpeg",
        title:"整套公寓型住宅·1室1卫1床",
        text:"【美式复古】一线江景/江景房源/大沙头码头/天字码头/珠江夜游/北京路/团一大/巨幕投影/安全消毒",
        star:"../../images/star.png",
        comment:"34",
        price:"￥228"
      },{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like4.jpeg",
        title:"整套普通公寓·1室1卫1床",
        text:"【逐梦】精心消毒/双地铁线/广州东站/体育中心/东方宝泰购物广场/落地窗/北欧风/单双床随机",
        star:"../../images/star.png",
        comment:"70",
        price:"￥179"
      },{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like5.jpg",
        title:"整套普通公寓·1室1卫1床",
        text:" 【哇小屋·罗马假日】看广州塔法式奶油屋！无清洁费神仙地段客村地铁站上盖近珠江新城直达机场长隆广交会",
        star:"../../images/star.png",
        comment:"23",
        price:"￥283"
      },{
        img:"cloud://myapp-6ga99ypi819d4ada.6d79-myapp-6ga99ypi819d4ada-1306404458/aribnb/like6.jpg",
        title:"整套公寓型住宅·1室1卫2床",
        text:" 【少女的祈祷】无清洁费神仙地段珠江新城复式欧式宫廷投影双地铁美领馆广州塔机场火车站长隆广交会",
        star:"../../images/star.png",
        comment:"88",
        price:"￥283"
      }]
      
    },
  // 事件处理函数
  listClick:function(event){
    var dataset = event.currentTarget.dataset;
    var id = dataset.id;
    wx.navigateTo({
      url: '/pages/detail/detail?id='+id,
    })
  },
  //国内、国际
  choose(){

  },

  // 获取地点
  getLocation: function () {
    var _this = this;
    wx.chooseLocation({
      success: function (res) {
        console.log(res);
       
        _this.setData({
          address: res.name
        })
      }
    })
  },
  // 日期
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  // 点击搜索跳转
  search:function(){
    var _this = this;
    var query = wx.createSelectorQuery().in(_this);
    query.selectViewport().scrollOffset()
    //#comm 跳转到指定id位置
    query.select("#sum").boundingClientRect();
    query.exec(function (res) {
      console.log(res);
      var miss = res[0].scrollTop + res[1].top - 10;
      wx.pageScrollTo({
        scrollTop: miss,
        duration: 300
      });
    });
},

  // 地点跳转
  toggle(e){
    this.setData({
      "i":e.target.dataset.index
    })
    var _this = this;
    console.log(e.target.dataset.index);
    db.collection('location').where({
    flag:e.target.dataset.index.toString()
    })
    .get({
      success: function(res) {
        // res.data 是包含以上定义的两条记录的数组
        // console.log(res.data)
        _this.setData({
          "location":res.data
        })
      }
    })
  },

  

  onLoad() {
  //  显示成都的房源
  var _this = this;
  db.collection('location').where({
  flag:"0"
  })
  .get({
    success: function(res) {
      // res.data 是包含以上定义的两条记录的数组
      // console.log(res.data)
      _this.setData({
        "location":res.data
      })
    }
  })

  },


})
